<form method="POST">
    <table>
        <thead>
            <tr>
                <th>Controller</th>
                {% for role in roles %}
                <th>{{role.name}}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            {% for permission in permissions %}
            <tr>
                <td>{{permission['controller']}}</td>
                {% for role in roles %}
                <?php if (in_array($role->id, $permission['roles'])) { ?>
                <td><input type="checkbox" checked name="permission[{{permission['controller']}}][]" value="{{role.id}}"/></td>
                <?php }else{ ?>
                <td><input type="checkbox" name="permission[{{permission['controller']}}][]" value="{{role.id}}"/></td>
                <?php } ?>
                {% endfor %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <button>Save</button>
</form>